package com.chenglong.supermarket.product.web;

import com.chenglong.supermarket.product.entity.CategoryEntity;
import com.chenglong.supermarket.product.service.CategoryService;
import com.chenglong.supermarket.product.vo.Catelog2Vo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @program: cheng-long-mall
 * @description:
 * @author: JIANGBEI
 * @create: 2021-05-15 09:07
 **/
@Controller
public class IndexController {
    @Autowired
    private CategoryService categoryService;
    @GetMapping({"/","/index.html"})
    public String indexPage(Model model){
        //查出一级分类
        List<CategoryEntity> categoryEntities = categoryService.getLevel1Catagorys();
        model.addAttribute("categorys",categoryEntities);
        return "index";
    }

    @ResponseBody
    @GetMapping("index/catalog.json")
    public Map<String, List<Catelog2Vo>> getCatalogJson(){
        Map<String, List<Catelog2Vo>> result =  categoryService.getCatalogJson();
        return result;
    }
}
